package dice.sinanya.db.coc;

import dice.sinanya.db.tools.DbUtil;
import dice.sinanya.entity.EntityCocList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;


/**
 * @author SitaNya
 * 日期: 2019-06-15
 * 电子邮箱: sitanya@qq.com
 * 维护群(QQ): 162279609
 * 有任何问题欢迎咨询
 * 类说明: 线索获取类，查询并包装成对象
 */
public class SelectCoc {
    private static final Logger log = LogManager.getLogger(SelectCoc.class.getName());


    public SelectCoc() {
//        初始化时无需逻辑
    }

    public ArrayList<EntityCocList> selectCoc() {
        ArrayList<EntityCocList> cocLists = new ArrayList<>();
        try (Connection conn = DbUtil.getConnection()) {
            String sql = "select id, jobName, min, max, skillValue, skill, othor from test.coc";
            try (PreparedStatement ps = conn.prepareStatement(sql)) {
                try (ResultSet set = ps.executeQuery()) {
                    while (set.next()) {
                        cocLists.add(new EntityCocList(
                                set.getInt("id"),
                                set.getString("jobName"),
                                set.getInt("min"),
                                set.getInt("max"),
                                set.getString("skill"),
                                set.getInt("othor"),
                                set.getString("skillValue")));
                    }
                }
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
        return cocLists;
    }


}
